<?php

namespace Modules\Shop\Http\Controllers;

use Illuminate\Support\Facades\Request;
use HiCommon\Service\PublicService;

class PublicController extends BaseController
{
    /**
     * 普通上传图片
     */
    public function uploadImg()
    {
        $res = upload_single_file($_FILES["file"]);

        echo json_encode(['code' => $res['state'], 'url' => $res['data']['url'],'src'=>$res['data']['src']]);
    }

    //随机数
    public function GetRandStr()
    {
        $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        $len = strlen($str) - 1;
        $randstr = '';
        for ($i = 0; $i < 6; $i++) {
            $num = mt_rand(0, $len);
            $randstr .= $str[$num];
        }
        return time().$randstr;
    }

    /**
     *省市区三级联动(获取省列表)
     */
    public function getProvinceList()
    {
        $list = PublicService::getProvinceList();

        dd(json_encode($list));
    }

    /**
     *省市区三级联动(获取城市列表)
     */
    public function getList()
    {
        $pid = Request::all();
        return PublicService::getCityList($pid);
    }

    /**
     * 区县坐标
     */
    public function areaCoordinate()
    {
        $data = Request::all();
        return PublicService::areaCoordinate($data);
    }

    /**
     * 物流追踪
     * 2019 11 15
     */
    public function logisticsTracking()
    {

        $order_id = intval(Request::get('id', 0));
        $type = intval(Request::get('type', 0));

        $res = PublicService::logistics_tracking($order_id, $type);
        echo_error($res);

        return view('shop::store_order.delivery', $res['data']);
    }


}
